package com.solr.product.service;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.solr.product.bean.Price;
import com.solr.product.bean.Product;
import com.solr.product.bean.ProductIndex;
import com.solr.product.dao.Obj2CloumnDao;
import com.solr.product.dao.PriceDao;
import com.solr.product.dao.ProductDao;


public class ProductService {

	
	@Autowired
	private ProductDao productDao;
	@Autowired
	private Obj2CloumnDao obj2CloumnDao;
	@Autowired
	private PriceDao priceDao;
	

	public List<ProductIndex> getIndex(int start, int limit){
		List<Product> productList = productDao.getProductPage(start, limit);
		
		if (productList == null || productList.isEmpty()) {
			return null;
		}
		List<ProductIndex> indexlist = new ArrayList<ProductIndex>();
		ProductIndex index ;
		for (Product product : productList) {
			index = new ProductIndex();
			int productid = product.getId();
			index.setProductid(productid);
			index.setName(product.getName());
			index.setPingyinname(product.getName());
			index.setStoreid(product.getStoreid());
			index.setCreatedate(product.getCreateDate());
			
			Price price = priceDao.getPriceByProductid(productid);
			index.setPrice(price);
			index.setPriceValue(price.getValue());
			List<Integer> column = obj2CloumnDao.getColumn(productid);
			index.setColumn(column);
			indexlist.add(index);
		}
		return indexlist;
	}
}
